﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDOS.Objects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace DDOS.Game_State
{
    class LevelSelectLayer : ScreenLayer
    {
        private Player player;
        private Texture2D[] isSelected;
        private Texture2D[] notSelected;
        private bool[] selected;
        private Vector2[] coord;
        private int pntr;
        /*private int googlePntr;
        private int yahooPntr;
        private int facebookPntr;
        private int microsoftPntr;
        private int applePntr;
        */
        

        public LevelSelectLayer(Player p)
            :base(true)
        {

            /* googlePntr = 0;
            applePntr = 0;
            yahooPntr = 0;
            microsoftPntr = 0;
            facebookPntr= 0;*/
            pntr = 0;
            player = p;
            isSelected = new Texture2D[5];
            notSelected = new Texture2D[5];
            selected = new bool[5];
            coord = new Vector2[5];
            isSelected[0] = ImageManager2D.Instance.Yahoos;
            isSelected[1] = ImageManager2D.Instance.Apples;
            isSelected[2] = ImageManager2D.Instance.Microsofts;
            isSelected[3] = ImageManager2D.Instance.Googles;
            isSelected[4] = ImageManager2D.Instance.Facebooks;
            notSelected[0] = ImageManager2D.Instance.Yahoo;
            notSelected[1] = ImageManager2D.Instance.Apple;
            notSelected[2] = ImageManager2D.Instance.Microsoft;
            notSelected[3] = ImageManager2D.Instance.Google;
            notSelected[4] = ImageManager2D.Instance.Facebook;
            selected[0] = true;
            selected[1] = false;
            selected[2] = false;
            selected[3] = false;
            selected[4] = false;
            coord[0] = new Vector2(150,150);
            coord[1] = new Vector2(375,400);
            coord[2] = new Vector2(575,250);
            coord[3] = new Vector2(665, 375);
            coord[4] = new Vector2(940,150);


        }
        public override void Update(Microsoft.Xna.Framework.GameTime gt)
        {

            if (InputManager.InputManagerInstance.GamePadButtonWasReleased(Buttons.B) || InputManager.InputManagerInstance.KeyWasReleased(Keys.Escape))
            {
                ScreenManager.Instance.CurrentScreen.RemoveLayer(this);
            }

            if (InputManager.InputManagerInstance.KeyWasReleased(Keys.Right) || InputManager.InputManagerInstance.GamePadThumbstickMovedRight(InputManager.GamePadThumbstick.right) || InputManager.InputManagerInstance.GamePadButtonWasReleased(Buttons.DPadRight))
            {
                selected[pntr] = false;
                pntr += 1;
                if (pntr > 4)
                    pntr = 4;
                selected[pntr] = true;
            }

            if (InputManager.InputManagerInstance.KeyWasReleased(Keys.Left) || InputManager.InputManagerInstance.GamePadThumbstickMovedLeft(InputManager.GamePadThumbstick.left) || InputManager.InputManagerInstance.GamePadButtonWasReleased(Buttons.DPadLeft))
            {
                selected[pntr] = false;
                pntr -= 1;
                if (pntr < 0)
                    pntr = 0;
                selected[pntr] = true;
            }

            if (InputManager.InputManagerInstance.GamePadButtonWasReleased(Buttons.A) || InputManager.InputManagerInstance.KeyWasReleased(Keys.Enter))
            {
                if(selected[0])
                {
                    SoundManager.Instance.Stop();
                    LevelScreen screen = new LevelScreen();
                    screen.PushLayer(new Level0(player));
                    ScreenManager.Instance.LoadScreen(screen);
                }
                if (selected[1])
                {
                    SoundManager.Instance.Stop();
                    LevelScreen screen = new LevelScreen();
                    screen.PushLayer(new Level1(player));
                    ScreenManager.Instance.LoadScreen(screen);
                }
            }
            
        }
        public override void Draw()
        {
            ScreenManager.Instance.CurrentSpriteBatch.Draw(ImageManager2D.Instance.WorldMap, Vector2.Zero, Color.White);
            for (int i = 0; i < 5; i++)
            {
                if (selected[i])
                {
                    ScreenManager.Instance.CurrentSpriteBatch.Draw(isSelected[i], coord[i], Color.White);
                }
                else
                {
                    ScreenManager.Instance.CurrentSpriteBatch.Draw(notSelected[i], coord[i], Color.White);
                }
            }
        }
    }
}
